/*
 * ConditionBlock.h
 *
 *  Created on: 23.04.2013
 *      Author: Lapchinskiy
 */
#include "Condition.h"
#ifndef CONDITIONBLOCK_H_
#define CONDITIONBLOCK_H_
template<class T>
class ConditionBlock: public Block
  {
public:
  ConditionBlock(Condition<T>* conditon);
  Block* step(void);
  ~ConditionBlock();

  void setCondition(Condition<T>* condition)
    {
      this->condition = condition;
    }

  void setNextNoBlock(Block* nextNoBlock)
    {
      this->nextNoBlock = nextNoBlock;
    }

  void setNextYesBlock(Block* nextYesBlock)
    {
      this->nextYesBlock = nextYesBlock;
    }
private:
  Block* nextYesBlock;
  Block* nextNoBlock;
  Condition<T>* condition;
  };

template<class T>
Block* ConditionBlock<T>::step(void)
  {
    return (condition->check() == true) ? nextYesBlock : nextNoBlock;
  }

template<class T>
ConditionBlock<T>::ConditionBlock(Condition<T>* conditon)
  {
    nextNoBlock=this;
    nextYesBlock=this;
    this->condition=conditon;
  }

#endif /* CONDITIONBLOCK_H_ */
